import 'package:flutter_folio/commands/commands.dart';
import 'package:flutter_folio/data/book_data.dart';
import 'package:flutter_folio/services/cloudinary/cloud_storage_service.dart';

class RefreshAllBooks extends BaseAppCommand {
  Future<List<ScrapBookData>?> run() async {
    print('load home data');
    List<ScrapBookData>? allBooks = await firebase.getAllBooks();
    if (allBooks != null) {
      CloudStorageService.addMaxSizeToUrlList<ScrapBookData>(
          allBooks, (s) => s.imageUrl, (s, url) => s.copyWith(imageUrl: url));
      booksModel.books = allBooks;
    }
    await Future.delayed(const Duration(seconds: 2), () async{


    });
    ScrapBookData data = ScrapBookData.fromJson({
      'documentId': '1',
      'key': '12',
      'title': 'book title 1',
      'desc': 'this is a book.',
      'creationTime': -1,
      'lastModifiedTime': -1,
      'pageCount': 0,
      'imageUrl': 'https://img2.baidu.com/it/u=3985265351,524868615&fm=253&fmt=auto&app=138&f=JPEG?w=640&h=372',
    });
    List<ScrapBookData> temp = [data,data,data,data,data,data,data,data,data,data];
    print('load home data temp.length = ${temp.length}');
    return temp;
    return booksModel.books;
  }
}
